<?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
//Route::get('/', function () {
//    return view('welcome');
//});
Route::get('user', '\App\Http\Controllers\Demo\UserController@index');
Route::match(['get', 'post'], 'user2', '\App\Http\Controllers\Demo\UserController@index');

Route::get('user3/{id}', '\App\Http\Controllers\Demo\UserController@index');

//Route::get('user4/{name?}', function (Request $request) {
////    dd($request::Route('name'));
////    dd($request::all());
//    dd($request::Route()->parameters());
//});
//Route::get('user5/{name}', function (Request $request) {
////    dd($request::Route('name'));
//    dd($request::all());
//})->where(['name' => '[A-Za-z]+']);
Route::get('user6', '\App\Http\Controllers\Demo\UserController@index')->name('user7');
Route::get('form', '\App\Http\Controllers\Demo\UserController@form');

//重定向
//Route::redirect('/here', '/user', 301);
//Route::get('redirect', function () {
//    return redirect()->route('user7');
//});
//路由分组
Route::middleware(['demo'])->group(function () {
    Route::get('index', 'Demo\GroupController@index');
});
//命名空间
Route::namespace('Admin')->group(function () {
    Route::get('index2', 'IndexController@index');
});
//子域名路由
//Route::domain('{account}/laravel.cn')->group(function () {
//    Route::get('aaa/{id}', function ($account, $id) {
//        return 'This is ' . $account . ' page of User ' . $id;
//    });
//});

//路由前缀  http://laravel.cn/admin/users
//Route::prefix('admin')->group(function () {
//    Route::get('users', function () {
//        // Matches The "/admin/users" URL
//    });
//});


//Route::get('token',Demo\CheckToken::class . "@index")->middleware('token');
//Route::get('token',Demo\CheckToken::class . "@index")->middleware('token','auth');
//Route::get('token',Demo\CheckToken::class . "@index")->middleware(\App\Http\Middleware\CheckToken::class);
Route::get('token', Demo\CheckToken::class . "@index");

Route::middleware(['role:123', 'token:456'])->group(function () {
    Route::get('role', Demo\CheckToken::class . "@index");
});
//Route::get('role', Demo\CheckToken::class . "@index")->middleware('token:456');

//csrf篇
//Route::get('form_without_csrf_token', function () {
//    return '<form method="POST" action="/hello_from_form"><button type="submit">提交</button></form>';
//});
//
//Route::get('form_with_csrf_token', function () {
//    return '<form method="POST" action="/hello_from_form">' . csrf_field() . '<button type="submit">提交</button></form>';
//});
//
//Route::post('hello_from_form', function () {
//    return 'hello laravel!';
//});
//控制器篇
//Route::get('user/{id}', 'Test\UserController@show');

//单动作控制器
//Route::get('user/{id}', 'Test\UserController');

//资源控制器
Route::resource('post','Test\PostController');
//Route::resources(['post' => 'Test\PostController']);
//部分资源路由
//Route::resource('post','Test\PostController',['only'=>'index']);
//Route::resource('post','Test\PostController',['except'=>'index']);
//API 资源路由
//Route::apiResources(['post' => 'Test\PostController']);//必须是一个数组
//包含 create 或 edit 方法的 API 资源控制器 php artisan make:controller API/PostController --api

//命名资源路由
//Route::resource('post','Test\PostController',['only'=>['index','show']]);
//Route::resource('post','Test\PostController',['only'=>['index','show'],'names'=>['show'=>'alias']]);//这里names没明白

//命名资源路由参数
//Route::resource('post', 'Test\PostController', ['parameters' => ['post' => 'admin_user']]);
//请求篇
//Route::any('test/{id?}', 'Test\UserController@test')->name('aaa');
Route::any('test/{id?}', 'Test\UserController@test');
//响应篇
Route::any('test2/{id}', 'Test\UserController@test2');
Route::any('test3/{id}', 'Test\UserController@test3')->name('user');
Route::any('redirect', 'Test\UserController@redirect');

//响应 重定向
//模版篇
Route::get('blade', function () {
    return view('child');
});